package com.bawei.image.glide

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.InternalCacheDiskCacheFactory
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.load.engine.cache.MemorySizeCalculator
import com.bumptech.glide.module.AppGlideModule

/**
 * 作者：Jason
 * 日期：2023/11/15
 * 描述：使用GlideModule初始化Glide内存和磁盘缓存大小
 */

@GlideModule
class GlideModule : AppGlideModule() {

    override fun applyOptions(context: Context, builder: GlideBuilder) {

        //设置内存缓存大小
        val memorySizeCalculator = MemorySizeCalculator.Builder(context).build()
        val memorySize = memorySizeCalculator.memoryCacheSize / 4L
        builder.setMemoryCache(LruResourceCache(memorySize))

        //磁盘缓存大小
        builder.setDiskCache(
            InternalCacheDiskCacheFactory(
                context,
                "imageCache",
                200 * 1024 * 1024
            )
        )
    }


}